package com.jiyinit.web.core.business.service;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.web.core.business.dao.TabCoreResourceDao;
import com.jiyinit.web.core.business.dto.TreePageRequest;
import com.jiyinit.web.core.business.entity.TabCoreResourceEntity;
import com.jiyinit.web.core.business.vo.ResourceVo;
import com.jiyinit.web.core.business.vo.RoleResourceVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author lishaochuan
 * @version 1.0
 * @date 2017/4/11 16:26
 * @since 1.0
 */
@Service("core.resourceServiceImpl")
public class ResourceServiceImpl {

    @Resource(name = "core.tabCoreOperateLogDao")
    private TabCoreResourceDao tabCoreResourceDao;

    /**
     * 添加资源树
     * @author lishaochuan
     * @create 2017/4/18 10:05
     * @param
     * @return
     */
    public int save(TabCoreResourceEntity tabCoreResource) {
        return tabCoreResourceDao.save(tabCoreResource);
    }


    /**
     * 修改资源树
     * @author lishaochuan
     * @create 2017/4/19 15:56
     * @param
     * @return
     */
    public int update(TabCoreResourceEntity tabCoreResource) {
        return tabCoreResourceDao.update(tabCoreResource);
    }


    /**
     * 根据用户ID获取用户权限树
     * @author lishaochuan
     * @create 2017/4/12 9:02
     * @param
     * @return
     */
    public List<ResourceVo> findResourceByUser(Integer userId){
        if(userId == -1){
            return tabCoreResourceDao.findAllResource(userId);
        }
        else
            return tabCoreResourceDao.findResourceByUser(userId);
    }


    /**
     * 查询角色权限树
     * @author lishaochuan
     * @create 2017/4/20 18:01
     * @param
     * @return
     */
    public List<RoleResourceVo> findResourceByRoleId(Integer roleId){
        return tabCoreResourceDao.findResourceByRoleId(roleId);
    }


    /**
     * 根据ID查询菜单
     * @author lishaochuan
     * @create 2017/4/17 18:21
     * @param
     * @return
     */
    public TabCoreResourceEntity selectById(Integer id){
        return tabCoreResourceDao.selectById(id);
    }

    /**
     * 根据parentId查询子节点树
     * @author lishaochuan
     * @create 2017/4/17 11:47
     * @param
     * @return
     */
    public List<TabCoreResourceEntity> selectByParentId(Integer parentId){
        return tabCoreResourceDao.selectByParentId(parentId);
    }


    /**
     * 分页根据parentId查询子节点树
     * @author lishaochuan
     * @create 2017/4/17 11:48
     * @param
     * @return
     */
    public PagingResult<TabCoreResourceEntity> selectPageByParentId(TreePageRequest treePageRequest){
        return tabCoreResourceDao.selectPageByParentId(treePageRequest);
    }
}
